{js:artTemplate}
<script type='text/javascript' src='{theme:javascript/artTemplate/area_select.js}'></script>
<script type='text/javascript' src='{theme:javascript/orderFormClass.js}'></script>
<script type='text/javascript'>
//创建订单表单实例
orderFormInstance = new orderFormClass();

//DOM加载完毕
jQuery(function(){
	//使用红包按钮
	$('#ticket_a').click(function()
	{
		//第一次打开时生成缓存数据
		if($.trim($('#ticket_show_box').text()) == '')
		{
			var ticketList = {echo:JSON::encode($this->prop)};
			for(var index in ticketList)
			{
				var ticketHtml = template.render('ticketTrTemplate',{item:ticketList[index]});
				$('#ticket_show_box').append(ticketHtml);
			}
		}

		$(this).toggleClass('fold');
		$(this).toggleClass('unfold');
		$('#ticket_box').toggle('slow');
	});

	//初始化地域联动JS模板
	template.compile("areaTemplate",areaTemplate);

	//收货地址数据
	orderFormInstance.addressInit("{$this->defaultAddressId}");

	//配送方式初始化
	orderFormInstance.deliveryInit("{$this->custom['delivery']}");

	//自提点初始化
	$('[name="takeself"]').val({$this->custom['takeself']});

	//支付方式
	orderFormInstance.paymentInit("{$this->custom['payment']}");

	//商品价格
	orderFormInstance.goodsSum = "{$this->final_sum}";
});

/**
 * 生成地域js联动下拉框
 * @param name
 * @param parent_id
 * @param select_id
 */
function createAreaSelect(name,parent_id,select_id)
{
	//生成地区
	$.getJSON("{url:/block/area_child}",{"aid":parent_id,"random":Math.random()},function(json)
	{
		$('[name="'+name+'"]').html(template.render('areaTemplate',{"select_id":select_id,"data":json}));
	});
}

//[address]保存到常用的收货地址
function address_save()
{
	if(orderFormInstance.addressCheck())
	{
		$.getJSON('{url:/simple/address_add}',$('form[name="order_form"]').serialize(),function(content){
			if(content.data)
			{
				var addressLiHtml = template.render('addressLiTemplate',{"item":content.data});
				$('.addr_list').prepend(addressLiHtml);
				$('input:radio[name="radio_address"]:first').trigger('click');
			}
			orderFormInstance.addressSave();
		});
	}
}

//[delivery]根据省份地区ajax获取配送方式
function get_delivery()
{
	var province = $('[name="province"]').val();
	var delivery = $('[name="delivery_id"]:checked').val();
	if(!province || !delivery)
	{
		return;
	}

	var goodsId   = [];
	var productId = [];
	var num       = [];
	$('[id^="deliveryFeeBox_"]').each(function(i)
	{
		var idValue = $(this).attr('id');
		var dataArray = idValue.split("_");

		goodsId.push(dataArray[1]);
		productId.push(dataArray[2]);
		num.push(dataArray[3]);
	});

	$.getJSON("{url:/block/order_delivery}",{"province":province,"distribution":delivery,"goodsId":goodsId,"productId":productId,"num":num},function(content){
		//地区无法送达
		if(content.if_delivery == 1)
		{
			$("#deliveryPrice").html('您选择地区部分商品无法送达');
			alert('您选择地区部分商品无法送达');
		}
		else
		{
			$("#deliveryPrice").html('￥'+content.price);
			orderFormInstance.protectPrice  = parseFloat(content.protect_price);
			orderFormInstance.deliveryPrice = parseFloat(content.price);
			orderFormInstance.doAccount();
		}
	});
}

//添加代金券
function add_ticket()
{
	var ticket_num = $('#ticket_num').val();
	var ticket_pwd = $('#ticket_pwd').val();

	if(ticket_num == '' || ticket_pwd == '')
	{
		alert('请填写卡号和密码');
		return '';
	}

	$.getJSON('{url:/block/add_download_ticket}',{"ticket_num":ticket_num,"ticket_pwd":ticket_pwd},function(content){
		if(content.isError == false)
		{
			is_success = true;
			$('[name="ticket_id"]').each(
				function()
				{
					if($(this).val() == content.data.id)
					{
						alert('代金券已经存在，不要重复添加');
						is_success = false;
					}
				}
			);

			if(is_success)
			{
				var ticketHtml = template.render('ticketTrTemplate',{item:content.data});
				$('#ticket_show_box').append(ticketHtml);
				$('[name="ticket_id"]').attr('checked',true);
				$('[name="ticket_id"]:last').trigger('click');
			}
			$('#ticket_num').val('');
			$('#ticket_pwd').val('');
		}
		else
		{
			alert(content.message);
		}
	});
}

//取消红包
function cancel_ticket()
{
	$('#ticket_a').trigger('click');
	$('[name="ticket_id"]').attr('checked',false);
	orderFormInstance.ticketPrice = 0;
	orderFormInstance.doAccount();
}

//选择自提点
function selectTakeself(deliveryId)
{
	art.dialog.open("{url:/block/takeself}",{
		title:'选择自提点',
		okVal:'选择',
		ok:function(iframeWin, topWin)
		{
			var takeselfJson = $(iframeWin.document).find('[name="takeselfItem"]:checked').val();

			if(!takeselfJson)
			{
				alert('请选择自提点');
				return false;
			}
			var json = $.parseJSON(takeselfJson);
			$('#takeself'+deliveryId).empty();
			$('[name="takeself"]').val(json.id);
			$('#takeself'+deliveryId).html(template.render('takeselfTemplate',{"item":json}));
			return true;
		}
	});
}

//选择代金券
function userTicket(seller_id,val)
{
	var sellerList = {echo:JSON::encode($this->seller)};
	var resultTicket = 0;
	for(var sid in sellerList)
	{
		if(seller_id == sid)
		{
			resultTicket = parseFloat(val) >= parseFloat(sellerList[sid]) ? parseFloat(sellerList[sid]) : parseFloat(val);
			orderFormInstance.ticketPrice = resultTicket;
			orderFormInstance.doAccount();
			return true;
		}
	}
	alert("请选择属于该商家的代金券");
	$('[name="ticket_id"]').attr('checked',false);
	return false;
}
</script>

<div class="wrapper clearfix">
	<div class="position mt_10"><span>您当前的位置：</span> <a href="{url:}"> 首页</a> » 填写核对订单信息</div>
	<div class="myshopping m_10">
		<ul class="order_step">
			<li class="current_prev"><span class="first"><a href='{if:IReq::get('id')}javascript:window.history.go(-1);{else:}{url:/simple/cart}{/if}'>1、查看购物车</a></span></li>
			<li class="current"><span>2、填写核对订单信息</span></li>
			<li class="last"><span>3、成功提交订单</span></li>
		</ul>
	</div>

	<form action='{url:/simple/cart3}' method='post' name='order_form' callback='orderFormInstance.isSubmit();'>

		<input type='hidden' name='timeKey' value='{echo:time()}' />
		<input type='hidden' name='direct_gid' value='{$this->gid}' />
		<input type='hidden' name='direct_type' value='{$this->type}' />
		<input type='hidden' name='direct_num' value='{$this->num}' />
		<input type='hidden' name='direct_promo' value='{$this->promo}' />
		<input type='hidden' name='direct_active_id' value='{$this->active_id}' />
		<input type='hidden' name='takeself' value='0' />

		<div class="cart_box m_10">
			<div class="title">填写核对订单信息</div>
			<div class="cont">

				<!--地址管理 开始-->
				<div class="wrap_box">
					<h3>
						<span class="orange">收货人信息</span>
						<a class="normal f12" href="javascript:void(0)" id="addressToggleButton" onclick="orderFormInstance.addressModToggle();">[退出]</a>
					</h3>

					<!--地址展示 开始-->
					<table class="form_table" id="address_show_box" style='display:none'>
						<col width="120" />
						<col />

						<tbody id="addressShowBox"></tbody>

						<!--收货地址展示模板-->
						<script type='text/html' id='addressShowTemplate'>
						<tr><th>收货人姓名：</th><td><%=accept_name%></td></tr>
						<tr><th>省份：</th><td><%=province_val%> <%=city_val%> <%=area_val%></td></tr>
						<tr><th>地址：</th><td><%=address%></td></tr>
						<tr><th>手机号码：</th><td><%=mobile%></td></tr>
						<tr><th>固定电话：</th><td><%=telphone%></td></tr>
						<tr><th>邮政编码：</th><td><%=zip%></td></tr>
						</script>
					</table>
					<!--地址展示 结束-->

					<!--收货表单信息 开始-->
					<div class="prompt_4 m_10" id='address_often'>
						<strong>常用收货地址</strong>
						<ul class="addr_list">
							{foreach:items=$this->addressList}
							<li>
								<label><input class="radio" name="radio_address" type="radio" value="{$item['id']}" onclick='orderFormInstance.addressSelected({echo:JSON::encode($item)});' />{$item['accept_name']}&nbsp;&nbsp;&nbsp;&nbsp;{$item['province_val']} {$item['city_val']} {$item['area_val']} {$item['address']}</label>
							</li>
							{/foreach}
							<li>
								<label><input type='radio' name='radio_address' onclick='orderFormInstance.addressEmpty();' value='' />其他收货地址</label>
							</li>
						</ul>

						<!--收货地址项模板-->
						<script type='text/html' id='addressLiTemplate'>
						<li>
							<label><input class="radio" name="radio_address" type="radio" value="<%=item['id']%>" onclick='orderFormInstance.addressSelected(<%=jsonToString(item)%>);' /><%=item['accept_name']%>&nbsp;&nbsp;&nbsp;&nbsp;<%=item['province_val']%> <%=item['city_val']%> <%=item['area_val']%> <%=item['address']%></label>
						</li>
						</script>
					</div>

					<div class="box" id='address_form'>
						<table class="form_table">
							<col width="90px" />
							<col />

							<tbody>
								<tr>
									<th>收货人姓名：</th><td><input class="normal" type="text" name="accept_name" pattern='required' alt='收件人姓名不能为空' /> <span>(*) 收货人的姓名</span> </td>
								</tr>
								<tr>
									<th>省份：</th>
									<td>
										<select name="province" child="city,area" onchange="areaChangeCallback(this);"></select>
										<select name="city" child="area" parent="province" onchange="areaChangeCallback(this);"></select>
										<select name="area" parent="city" pattern="required" alt="请选择收货地区"></select>
										<span>(*) 收货地区</span>
									</td>
								</tr>
								<tr>
									<th>地址：</th><td><input class="normal" name='address' type="text" alt='格式不正确' pattern='required' /> <span>(*) 收货地址</span></td>
								</tr>
								<tr>
									<th>手机号码：</th><td><input class="middle" name='mobile' type="text" pattern='mobi' alt='格式不正确' /> <span>(*) 收货人的手机号，用于接收发货通知短信及送货前确认</span></td>
								</tr>
								<tr>
									<th>固定电话：</th><td><input class="middle" type="text" pattern='phone' name='telphone' empty alt='格式不正确' /></td>
								</tr>
								<tr>
									<th>邮政编码：</th><td><input class="middle" name='zip' empty type="text" pattern='zip' alt='格式不正确' /></td>
								</tr>
							</tbody>
						</table>
					</div>
					<!--收货表单信息 结束-->

					<label class="btn_orange3" id='address_save_button'><input type="button" value="保存收货人地址" onclick="address_save();" /></label>
				</div>
				<!--地址管理 结束-->

				<!--配送方式 开始-->
				<div class="wrap_box" id='deliveryBox' style='display:none'>
					<h3>
						<span class="orange">配送方式</span>
						<a class="normal f12" href="javascript:void(0)" id='deliveryToggleButton' onclick="orderFormInstance.deliveryModToggle();">[关闭]</a>
					</h3>

					<!--配送展示 开始-->
					<table class="form_table" id="delivery_show_box" style='display:none'>
						<col width="120px" />
						<col />

						<tbody id="deliveryShowBox"></tbody>

						<!--配送方式展示模板-->
						<script type='delivery' id='deliveryShowTemplate'>
						<tr><th>配送方式：</th><td><%=name%></td></tr>
						<tr><th>运费：</th><td id="deliveryPrice"></td></tr>
						</script>
					</table>
					<!--配送展示 结束-->

					<!--配送修改 开始-->
					<table width="100%" class="border_table m_10" id='delivery_form'>
						<col width="180px" />
						<col />

						<tbody>
							{set:$deliveryData = Api::run('getDeliveryList')}
							{foreach:items = $deliveryData}
							<tr>
								<th><label><input type="radio" name="delivery_id" value="{$item['id']}" paytype="{$item['type']}" onclick='orderFormInstance.deliverySelected({echo:JSON::encode($item)});' />{$item['name']}</label></th>
								<td>
									{$item['description']}

									{if:$item['type'] == 2}
									<a href="javascript:selectTakeself({$item['id']});"><span class="red">选择自提点</span></a>
									<span id="takeself{$item['id']}"></span>
									{/if}
								</td>
							</tr>
							{/foreach}
						</tbody>

						<script type='text/html' id='takeselfTemplate'>
							<%=item['province_str']%> <%=item['city_str']%> <%=item['area_str']%> <%=item['address']%> <%=item['name']%> <%=item['phone']%> <%=item['mobile']%>
						</script>

						<tfoot>
							<th>指定送货时间：</th>
							<td>
								<label class='attr'><input type='radio' name='accept_time' checked="checked" value='任意' />任意</label>
								<label class='attr'><input type='radio' name='accept_time' value='周一到周五' />周一到周五</label>
								<label class='attr'><input type='radio' name='accept_time' value='周末' />周末</label>
							</td>
						</tfoot>
					</table>
					<!--配送修改 结束-->

					<label class="btn_orange3"><input type="button" id="delivery_save_button" onclick="orderFormInstance.deliverySave();" value="保存配送方式" /></label>
				</div>
				<!--配送方式 结束-->

				<!--支付方式 开始-->
				<div class="wrap_box" id='paymentBox' style='display:none'>
					<h3>
						<span class="orange">支付方式</span>
						<a class="normal f12" href="javascript:void(0)" id='paymentToggleButton' onclick="orderFormInstance.paymentModToggle();">[关闭]</a>
					</h3>

					<table width="100%" class="border_table" id='payment_form'>
						<colgroup>
							<col width="200px" />
							<col />
						</colgroup>
						{set:$paymentList=Api::run('getPaymentList')}
						{foreach:items = $paymentList}
						{set:$paymentPrice = CountSum::getGoodsPaymentPrice($item['id'],$this->sum);}
						<tr>
							<th><label><input class="radio" name="payment" alt="{$paymentPrice}" onclick='orderFormInstance.paymentSelected({echo:JSON::encode($item)});' title="{$item['name']}" type="radio" value="{$item['id']}" />{$item['name']}</label></th>
							<td>{$item['note']} 支付手续费：￥{$paymentPrice}</td>
						</tr>
						{/foreach}
					</table>

					<table class="form_table" id="payment_show_box" style='display:none'>
						<col width="120px" />
						<col />
						<tbody id="paymentShowBox"></tbody>
					</table>

					<!--支付方式模板-->
					<script type='text/html' id='paymentShowTemplate'>
						<tr>
							<th>支付方式：</th>
							<td><%=name%></td>
						</tr>
					</script>

					<label class="btn_orange3" id='payment_save_button'><input type="button" onclick="orderFormInstance.paymentSave();" value="保存支付方式" /></label>
				</div>
				<!--支付方式 结束-->

				<!--订单留言 开始-->
				<div class="wrap_box">
					<h3>
						<span class="orange">订单附言</span>
						<a class="normal f12" href="javascript:void(0)" id='messageToggleButton' onclick="orderFormInstance.messageModToggle();">[修改]</a>
					</h3>

					<table width="100%" class="border_table" id='message_show_box'>
						<col width="120px" />
						<col />
						<tbody>
							<tr>
								<th>订单附言：</th>
								<td id="messageShowBox"></td>
							</tr>
						</tbody>
					</table>

					<table width="100%" class="form_table" id='message_form' style='display:none'>
						<col width="120px" />
						<col />
						<tr>
							<th>订单附言：</th>
							<td><input class="normal" type="text" name='message' /></td>
						</tr>
					</table>

					<label class="btn_orange3" id='message_save_button' style='display:none'><input type="button" onclick="orderFormInstance.messageSave();" value="保存订单附言" /></label>
				</div>
				<!--订单留言 结束-->

				<!--购买清单 开始-->
				<div class="wrap_box">

					<h3><span class="orange">购买的商品</span></h3>

					<div class="cart_prompt f14 t_l m_10" {if:empty($this->promotion)}style="display:none"{/if}>
						<p class="m_10 gray"><b class="orange">恭喜，</b>您的订单已经满足了以下优惠活动！</p>
						{foreach:items = $this->promotion}
						<p class="indent blue">{$item['plan']}，{$item['info']}</p>
						{/foreach}
					</div>

					<table width="100%" class="cart_table t_c">
						<colgroup>
							<col width="115px" />
							<col />
							<col width="80px" />
							<col width="80px" />
							<col width="80px" />
							<col width="80px" />
							<col width="80px" />
						</colgroup>

						<thead>
							<tr>
								<th>图片</th>
								<th>商品名称</th>
								<th>赠送积分</th>
								<th>单价</th>
								<th>优惠</th>
								<th>数量</th>
								<th class="last">小计</th>
							</tr>
						</thead>

						<tbody>
							<!-- 商品展示 开始-->
							{foreach:items = $this->goodsList}
							<tr>
								<td><img src="{url:/pic/thumb/img/$item[img]/w/66/h/66}" width="66px" height="66px" alt="{$item['name']}" title="{$item['name']}" /></td>
								<td class="t_l">
									<a href="{url:/site/products/id/$item[goods_id]}" class="blue">{$item['name']}</a>
									{if:isset($item['spec_array'])}
									<p>
									{set:$spec_array=Block::show_spec($item['spec_array']);}
									{foreach:items=$spec_array item=$specValue key=$specName}
										{$specName}：{$specValue} &nbsp&nbsp
									{/foreach}
									</p>
									{/if}
								</td>
								<td>{$item['point']}</td>
								<td><b>￥{$item['sell_price']}</b></td>
								<td>减￥{$item['reduce']}</td>
								<td>{$item['count']}</td>
								<td id="deliveryFeeBox_{$item['goods_id']}_{$item['product_id']}_{$item['count']}"><b class="red2">￥{$item['sum']}</b></td>
							</tr>
							{/foreach}
							<!-- 商品展示 结束-->
						</tbody>
					</table>
				</div>
				<!--购买清单 结束-->

			</div>
		</div>

		<!--金额结算-->
		<div class="cart_box" id='amountBox' style='display:none'>
			<div class="cont_2">
				<strong>结算信息</strong>
				<div class="pink_box">
					<p class="f14 t_l">{if:$this->final_sum != $this->sum}优惠后总金额{else:}商品总金额{/if}：<b>{$this->final_sum}</b> - 代金券：<b name='ticket_value'>0</b> + 税金：<b id='tax_fee'>0</b> + 运费总计：<b id='delivery_fee_show'>0</b> + 保价：<b id='protect_price_value'>0</b> + 支付手续费：<b id='payment_value'>0</b></p>

					<a href="javascript:void(0)" id="ticket_a" class="fold" hidefocus>
						<b class="orange">使用代金券</b>
					</a>

					<!--代金券列表-->
					<div class="cart_box t_l gray" style='display:none' id='ticket_box'>
						<div class="cont">
							<table width="100%" class="list_table m_10">
								<colgroup>
									<col width="220px" />
									<col />
									<col width="250px" />
								</colgroup>

								<caption class="t_l">
									<b>请选择要使用的代金券</b>
									<span class='red2'>(注：代金券仅能抵扣商品金额)</span>：
								</caption>

								<tbody id='ticket_show_box'></tbody>

								<!--代金券模板-->
								<script type='text/html' id='ticketTrTemplate'>
								<tr>
									<td class="t_l"><label><input class="radio" name="ticket_id" onclick="userTicket(<%=item.seller_id%>,<%=item.value%>);" type="radio" value="<%=item.id%>" /><%=item.name%></label></td>
									<td class="t_l">编号：<%=item.card_name%></td>
									<td class="t_r">优惠：<span class="red2">￥<b><%=item.value%></b></span></td>
								</tr>
								</script>

								<tr>
									<td><label class="btn_gray_m"><input type="button" onclick="cancel_ticket();" value="取消代金券" /></label></td>
									<td colspan=2>
										有实体代金券？
										卡号：<input type='text' class='gray_m' id='ticket_num' />
										密码：<input type='password' class='gray_m' id='ticket_pwd' />
										<label class="btn_gray_m"><input type="button" onclick="add_ticket();" value="添加" /></label>
									</td>
								</tr>

							</table>

							<p class="t_r">使用了代金券 可以优惠 <b class="red2" name='ticket_value'>0</b> 元</p>
						</div>
					</div>

				</div>
				<hr class="dashed" />
				<div class="pink_box gray m_10">
					<table width="100%" class="form_table t_l">
						<col width="220px" />
						<col />
						<col width="250px" />
						<tr>
							<td>是否需要发票？(税金:￥{$this->goodsTax}) <input class="radio" onclick="orderFormInstance.doAccount();$('#tax_title').toggle();" name="taxes" type="checkbox" value="{$this->goodsTax}" /></td>
							<td><label id="tax_title" class='attr' style='display:none'>发票抬头：<input type='text' class='normal' name='tax_title' /></label></td>
							<td class="t_r"><b class="price f14">应付总额：<span class="red2">￥<b id='final_sum'>{$this->final_sum}</b></span>元</b></td>
						</tr>
					</table>
				</div>
				<p class="m_10 t_r"><input type="submit" class="submit_order" /></p>
			</div>
		</div>
	</form>
</div>